package com.diy.sigmund.diyuser.controller;

import cn.hutool.core.util.RandomUtil;
import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.entity.enumerate.ResponseEnum;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 积分处理控制类
 *
 * @author ylm-sigmund
 * @since 2021/11/5 15:59
 */
@RestController
@RequestMapping("/user/pointProcessing")
public class PointProcessingController {

    private static final Logger log = LoggerFactory.getLogger(PointProcessingController.class);

    /**
     * 减少积分
     *
     * @return ResultMsg
     */
    @PostMapping("/decrease")
    public ResultMsg decrease() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            log.error("", e);
        }
        return RandomUtil.randomBoolean() ? ResultMsg.success() : ResultMsg.fail(ResponseEnum.INTERNAL_SERVER_ERROR);
    }
}
